package com.eian.boot.config.mybatis;

import com.eian.boot.common.interceptor.DataScopeInterceptor;
import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author alex.meng
 * @createTime 2025-08-29
 * @description mybatis 配置
 */
@Configuration
@MapperScan("com.eian.**.mapper")
@AllArgsConstructor
public class MyBatisConfig {

    private final SqlSessionFactory sqlSessionFactory;
    private final DataScopeInterceptor dataScopeInterceptor;

    /**
     * 注册数据权限拦截器
     */
    @PostConstruct
    public void addInterceptors() {
        sqlSessionFactory.getConfiguration().addInterceptor(dataScopeInterceptor);
    }
}
